package cn.springboot.osbulkparts.controller.warehouse;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import cn.springboot.osbulkparts.common.CommonResultInfo;
import cn.springboot.osbulkparts.common.OSLanguage;
import cn.springboot.osbulkparts.common.entity.CommonEntity;
import cn.springboot.osbulkparts.entity.MPackingDetailsInfoEntity;
import cn.springboot.osbulkparts.entity.TDictDataEntity;
import cn.springboot.osbulkparts.service.PackingDetailsListService;
import cn.springboot.osbulkparts.service.ReportOrderDetailService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("/packingDetailsList")
public class PackingDetailsListController {
	@Autowired
	private PackingDetailsListService packingDetailsListService;
	@Autowired
	private ReportOrderDetailService reportOrderDetailService;

	
	@ApiOperation(value="页面初始化", notes="获取页面初始化数据")
	@GetMapping("/init")
	public CommonResultInfo<Map<String, List<TDictDataEntity>>> initViews(@RequestHeader String lang){
		return  packingDetailsListService.initViews(lang,OSLanguage.localeToVueSuffix(lang));
	}
	
	@ApiOperation(value="获取装箱明细信息列表信息", notes="获取装箱明细信息列表信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "MPackingDetailsInfoEntity", value = "装箱明细实体类", required = true, dataType = "body", paramType = "body"),
		@ApiImplicitParam(name = "pageNum", value = "分页-当前页码(默认1)", required = true, dataType = "String", paramType = "body"),
		@ApiImplicitParam(name = "pageSize", value = "分页-总页数(默认10)", required = true, dataType = "String", paramType = "body")
	})
	@GetMapping("/getPackingDetailsList")
	public CommonResultInfo<?> getPackingDetailsList(
			MPackingDetailsInfoEntity mPackingDetailsInfoEntity,
			@RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue="50") int pageSize,
			HttpServletRequest request, Authentication auth,@RequestHeader String lang){
		mPackingDetailsInfoEntity.setLanguageFlag(OSLanguage.localeToTableSuffix(lang));
		return  packingDetailsListService.getPackingDetailsList(mPackingDetailsInfoEntity,pageNum,pageSize,auth,OSLanguage.localeToVueSuffix(lang));
	}
	
	@ApiOperation(value="获取装箱明细信息", notes="获取装箱明细信息的详细数据")
	@ApiImplicitParam(name = "MPackingDetailsInfoEntity", value = "装箱明细实体类", required = true, dataType = "body", paramType = "body")
	@GetMapping("/getPackingDetailsInfo")
	public CommonResultInfo<?> getPackingDetailsInfo(MPackingDetailsInfoEntity mPackingDetailsInfoEntity,@RequestHeader String lang){
		mPackingDetailsInfoEntity.setLanguageFlag(OSLanguage.localeToTableSuffix(lang));
		return  packingDetailsListService.getPackingDetailsInfo(mPackingDetailsInfoEntity,OSLanguage.localeToVueSuffix(lang));
	}
	
    @ApiOperation(value="添加装箱明细信息", notes="添加一条新的装箱明细信息")
    @ApiImplicitParam(name = "MPackingDetailsInfoEntity", value = "装箱明细实体类", required = true, dataType = "body", paramType = "body")
    @PostMapping("/addPackingDetailsInfo")
	public CommonResultInfo<?> addPackingDetailsInfo(@RequestBody MPackingDetailsInfoEntity mPackingDetailsInfoEntity,Authentication auth,@RequestHeader String lang){
		return  packingDetailsListService.addPackingDetailsInfo(mPackingDetailsInfoEntity,auth,OSLanguage.localeToVueSuffix(lang));
	}
    
    @ApiOperation(value="更新装箱明细信息", notes="更新一条新的装箱明细信息")
    @ApiImplicitParam(name = "MPackingDetailsInfoEntity", value = "装箱明细实体类", required = true, dataType = "body", paramType = "body")
    @PutMapping("/updatePackingDetailsInfo")
	public CommonResultInfo<?> updatePackingDetailsInfo(@RequestBody MPackingDetailsInfoEntity mPackingDetailsInfoEntity,Authentication auth,@RequestHeader String lang){
		return  packingDetailsListService.updatePackingDetailsInfo(mPackingDetailsInfoEntity,auth,OSLanguage.localeToVueSuffix(lang));
	}
    
    @ApiOperation(value="装箱明细信息导入", notes="excel的装箱明细信息数据文件导入")
    @ApiImplicitParam(name = "excleFile", value = "库存数据文件", required = true, dataType = "body", paramType = "body")
    @PostMapping("/importExcel")
    public CommonResultInfo<?> ImportExcelData(
            @RequestParam("file") MultipartFile excleFile,HttpServletRequest request,Authentication auth,@RequestHeader String lang) {
		return  packingDetailsListService.importExcel(excleFile,request,auth,lang,OSLanguage.localeToVueSuffix(lang));
    }
    
	@ApiOperation(value="删除装箱明细信息", notes="删除装箱明细信息")
	@ApiImplicitParam(name = "commonEntity", value = "共同实体类", required = true, dataType = "body", paramType = "body")
	@PutMapping("/deletePackingDetails")
	public CommonResultInfo<?> batchDeletion(@RequestBody CommonEntity commonEntity, Authentication auth,@RequestHeader String lang){
		return  packingDetailsListService.deleteBatchByIds(commonEntity,auth,OSLanguage.localeToVueSuffix(lang));
	}

	@ApiOperation(value="装箱明细信息导出", notes="装箱明细信息导出")
	@ApiImplicitParam(name = "mPackingDetailsInfoEntity", value = "装箱明细实体类", required = true, dataType = "body", paramType = "body")
	@PostMapping("/exportData")
	public Object downExcel(@RequestBody MPackingDetailsInfoEntity mPackingDetailsInfoEntity,@RequestHeader String lang) {
		mPackingDetailsInfoEntity.setLanguageFlag(OSLanguage.localeToTableSuffix(lang));
		return  packingDetailsListService.downloadExcel(mPackingDetailsInfoEntity,OSLanguage.localeToVueSuffix(lang));
	}

	@ApiOperation(value="根据物料号从物料表和发货表中获取数据", notes="根据物料号从物料表和发货表中获取数据")
	@ApiImplicitParam(name = "MPackingDetailsInfoEntity", value = "装箱明细实体类", required = true, dataType = "body", paramType = "body")
	@GetMapping("/getPackingDetailsInfoBymaterialCode")
	public CommonResultInfo<?> getPackingDetailsInfoBymaterialCode(MPackingDetailsInfoEntity mPackingDetailsInfoEntity,@RequestHeader String lang){
		mPackingDetailsInfoEntity.setLanguageFlag(OSLanguage.localeToTableSuffix(lang));
		return  packingDetailsListService.getPackingDetailsInfoBymaterialCode(mPackingDetailsInfoEntity,OSLanguage.localeToVueSuffix(lang));
	}

	@ApiOperation(value="批量修改", notes="批量修改")
	@ApiImplicitParam(name = "MPackingDetailsInfoEntity", value = "装箱明细实体类", required = true, dataType = "body", paramType = "body")
	@PutMapping("/updatePackingDetailsList")
	public CommonResultInfo<?> updatePackingDetailsList(@RequestBody CommonEntity commonEntity,Authentication auth,@RequestHeader String lang){
		return  packingDetailsListService.updatePackingDetailsList(commonEntity,auth,OSLanguage.localeToVueSuffix(lang));
	}
	
	@ApiOperation(value="分票分箱明细报表导出", notes="分票分箱明细报表导出")
	@ApiImplicitParam(name = "mPackingDetailsInfoEntity", value = "装箱明细实体类", required = true, dataType = "body", paramType = "body")
	@PostMapping("/exportSubboxData")
	public Object downSubBoxExcel(@RequestBody MPackingDetailsInfoEntity mPackingDetailsInfoEntity,Authentication auth,@RequestHeader String lang) {
		mPackingDetailsInfoEntity.setLanguageFlag(OSLanguage.localeToTableSuffix(lang));
		return  reportOrderDetailService.ExportSubBoxReport(mPackingDetailsInfoEntity,OSLanguage.localeToVueSuffix(lang),auth);
	}

	@ApiOperation(value="箱单发票报表导出", notes="箱单发票报表导出")
	@ApiImplicitParam(name = "mPackingDetailsInfoEntity", value = "装箱明细实体类", required = true, dataType = "body", paramType = "body")
	@PostMapping("/exportBoxInvoice")
	public Object downBoxInvoiceExcel(@RequestBody MPackingDetailsInfoEntity mPackingDetailsInfoEntity,Authentication auth,@RequestHeader String lang) {
		mPackingDetailsInfoEntity.setLanguageFlag(OSLanguage.localeToTableSuffix(lang));
		return  reportOrderDetailService.ExportPackingListReport(mPackingDetailsInfoEntity,OSLanguage.localeToVueSuffix(lang),auth);
	}

	@ApiOperation(value="保险发票样本报表导出", notes="保险发票样本报表导出")
	@ApiImplicitParam(name = "mPackingDetailsInfoEntity", value = "装箱明细实体类", required = true, dataType = "body", paramType = "body")
	@PostMapping("/exportInsuranceReport")
	public Object insuranceReport(@RequestBody MPackingDetailsInfoEntity mPackingDetailsInfoEntity,Authentication auth,@RequestHeader String lang) {
		mPackingDetailsInfoEntity.setLanguageFlag(OSLanguage.localeToTableSuffix(lang));
		return  reportOrderDetailService.insuranceReport(mPackingDetailsInfoEntity,OSLanguage.localeToVueSuffix(lang),auth);
	}
	
	@ApiOperation(value="附件订单计划报表导出", notes="附件订单计划报表导出")
	@ApiImplicitParam(name = "mPackingDetailsInfoEntity", value = "装箱明细实体类", required = true, dataType = "body", paramType = "body")
	@PostMapping("/exportAttadchmentData")
	public Object downAttachExcel(@RequestBody MPackingDetailsInfoEntity mPackingDetailsInfoEntity,Authentication auth,@RequestHeader String lang) {
		mPackingDetailsInfoEntity.setLanguageFlag(OSLanguage.localeToTableSuffix(lang));
		return  reportOrderDetailService.ExportattachmentListReport(mPackingDetailsInfoEntity,OSLanguage.localeToVueSuffix(lang),auth);
	}
	
	@ApiOperation(value="提单样本报表导出", notes="提单样本报表导出")
	@ApiImplicitParam(name = "mPackingDetailsInfoEntity", value = "装箱明细实体类", required = true, dataType = "body", paramType = "body")
	@PostMapping("/exportBookingListData")
	public Object downBookingExcel(@RequestBody MPackingDetailsInfoEntity mPackingDetailsInfoEntity,Authentication auth,@RequestHeader String lang) {
		mPackingDetailsInfoEntity.setLanguageFlag(OSLanguage.localeToTableSuffix(lang));
		return  reportOrderDetailService.ExportBookingListReport(mPackingDetailsInfoEntity,OSLanguage.localeToVueSuffix(lang),auth);
	}

	@ApiOperation(value="提单样本（铁路）", notes="提单样本（铁路）")
	@ApiImplicitParam(name = "mPackingDetailsInfoEntity", value = "装箱明细实体类", required = true, dataType = "body", paramType = "body")
	@PostMapping("/billOfLadingSampleReport")
	public Object billOfLadingSampleReportExcel(@RequestBody MPackingDetailsInfoEntity mPackingDetailsInfoEntity,Authentication auth,@RequestHeader String lang) {
		mPackingDetailsInfoEntity.setLanguageFlag(OSLanguage.localeToTableSuffix(lang));
		return  reportOrderDetailService.billOfLadingSampleReport(mPackingDetailsInfoEntity,OSLanguage.localeToVueSuffix(lang),auth);
	}
}
